<?php

namespace app\admin\logic\zhxy;

use app\admin\logic\zhxy\Business\AbstractBusiness;
use app\admin\model\Budget;
use app\admin\model\Device;
use app\admin\model\Intention;
use app\admin\model\Projectlib;
use app\admin\model\Subject;

/**
 * 业务处理工具
 *
 * @mixin AbstractBusiness
 */
class Business
{

    public $row;
    /**
     * 业务 业务处理
     *
     * @var Business\Intention|AbstractBusiness |null
     */
    private $business = null;
    use WorkFlow;

    public function __construct($row)
    {
        $this->row = $row;

        if ($row instanceof Projectlib) {
            $this->business = new \app\admin\logic\zhxy\Business\Projectlib($row, $this);
        }
        if ($row instanceof Intention) {
            $this->business = new \app\admin\logic\zhxy\Business\Intention($row, $this);
        }
        if ($row instanceof Subject) {
//            app\admin\model\Subject
            $this->business = new \app\admin\logic\zhxy\Business\Subject($row, $this);
        }
        if ($row instanceof Budget) {
//            app\admin\model\Subject
            $this->business = new \app\admin\logic\zhxy\Business\Budget($row, $this);
        }
        if ($row instanceof Device) {
//            app\admin\model\Subject
            $this->business = new \app\admin\logic\zhxy\Business\Device($row, $this);
        }
    }


    /**
     * 是否定义处理器
     *
     * @return bool
     */
    public function isBusiness()
    {
        return !is_null($this->business);
    }

    public function __call($name, $arguments)
    {
        if (!$this->isBusiness()) {
            throw new \LogicException("没有定义 业务处理器");
        }

        return call_user_func_array([ $this->business, $name ], $arguments);
    }


}